/**
 * Created by Eoly on 2016/12/31.
 */
function PlayerTouch() {
    var _this = this;

    this.touchPoint = new Point();

    //需外部设置
    this.canvas = null;
    this.plane = null;


    this.distance = 0;
    this.deg = 0;
    this.sensitivity = 0.8;

    this.openTouch = function () {

        window.addEventListener("touchstart", function (e) {
            _this.touchPoint.x = e.touches[0].clientX;
            _this.touchPoint.y = e.touches[0].clientY;
            e.preventDefault();
            e.preventDefault();
        });

        window.addEventListener("touchmove", function (e) {
            e.preventDefault();
            e.stopPropagation();
            var movePoint = new Point(e.touches[0].clientX, e.touches[0].clientY);
            _this.distance = _this.touchPoint.getDistanceFromAnotherPoint(movePoint);
            _this.deg = _this.touchPoint.getDegFromAnotherPoint(movePoint);
            if (_this.plane != null) {
                _this.plane.runningTrack.direction = _this.deg;
                _this.plane.runningTrack.speed = _this.distance * _this.sensitivity;
                _this.plane.runWithTrack();
                _this.canvas.drawAll();
                _this.touchPoint = movePoint;
                _this.plane.checkEndShoot();
            }

        }, {passive: false});

    };
}